
        <form method="POST" onSubmit="return false;">
            <div class="row-fluid">
                <div class="span3">
                    <label for="auto-adjust-scan-ip-thread-num">{{ _("Auto-adjust scan thread count") }}<a href="https://github.com/XX-net/XX-Net/wiki/GoAgent-Auto-adjust-scan-ip-thread-num" target="_blank">({{ _("Help") }})</a></label>
                </div> <!-- .span3 -->
                <div class="span9">
                    <input id="auto-adjust-scan-ip-thread-num" type="checkbox" data-toggle="switch" />
                </div> <!-- .span9 -->
            </div> <!-- .row-fluid -->
            <div class="row-fluid">
                <div class="span3">
                    <label for="scan-ip-thread-num">{{ _("Max scan thread count") }}</label>
                </div> <!-- .span3 -->
                <div class="span6">
                    <input id="scan-ip-thread-num" type="text" />
                </div> <!-- .span6 -->
            </div> <!-- .row-fluid -->
            <div class="row-fluid">
                <div class="span3">
                    <label for="ip-range-content">{{ _("IP range list") }}(<a href="https://github.com/XX-net/XX-Net/wiki/GoAgent-Scan-Ip-Range-Format" target="_blank">{{ _("Supporting formats") }}</a>)</label>
                </div> <!-- .span3 -->
                <div class="span9">
                    <textarea id="ip-range-content" rows="10"></textarea>
                </div> <!-- .span9 -->
            </div> <!-- .row-fluid -->
            <div class="row-fluid">
                <div class="span12">
                    <button class="btn btn-primary btn-block" id="submit" type="submit">{{ _("Submit") }}</button>
                </div> <!-- .span12 -->
            </div> <!-- .row-fluid -->
        </form>
<script type="text/javascript">
    $(function() {
        $('[data-toggle=switch]').wrap('<div class="switch" />').parent().bootstrapSwitch();
    });
</script>
<script type="text/javascript">
    $(function() {
        $.ajax({
            type: 'POST',
            url: '/module/gae_proxy/control/config?cmd=get_config',
            dataType: 'JSON',
            success: function(result) {
                if ( result['auto_adjust_scan_ip_thread_num'] != 0 ) {
                    $( "#auto-adjust-scan-ip-thread-num").parent().removeClass('switch-off');
                    $( "#auto-adjust-scan-ip-thread-num").parent().addClass('switch-on');

                    $( "#auto-adjust-scan-ip-thread-num").prop('checked', true);
                }
                $('#scan-ip-thread-num').val(result['scan_ip_thread_num']);
            },
            error: function(){
                tip('{{ _("Failed reading the settings") }}', 'error');
            }
        });
    });

    $('#ip-range-content').load('/module/gae_proxy/control/scan_ip?cmd=get_range');
</script>
<script type="text/javascript">
    $('#submit').click(function() {
        // set_auto_adjust_scan_ip_thread_num
        var isChecked = $("#auto-adjust-scan-ip-thread-num").is(':checked');

        // scan-ip-thread-num
        var scanIpThreadNum = $('#scan-ip-thread-num').val();

        // ip-range
        var ipRangeContent = $('#ip-range-content').val();
        
        $.ajax({
            type: 'POST',
            url: '/module/gae_proxy/control/scan_ip?cmd=update',
            data: {"auto_adjust_scan_ip_thread_num": isChecked ? 1 : 0,
                   "scan_ip_thread_num": scanIpThreadNum,
                   "ip_range": ipRangeContent},
            dataType: 'JSON',
            success: function(result) {
                if ( result['res'] == 'success' ) {
                    tip('{{ _("Settings saved successfully") }}', 'success');
                } else {
                    tip('{{ _("Unkown error occurred") }}', 'error');
                }
            }
        });

    });
</script>
